﻿<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-task-list" lay-data="" lay-filter="LAY-task-list"></table>
        </div>
    </div>
</div>
<script type="text/html" id="checkboxTpl">
    <input type="checkbox" name="Enabled" value="{{d.Id}}" title="锁定" lay-filter="lockDemo" {{ d.Enabled ? 'checked' : '' }}>
</script>

<script>
    layui.use(['index','table','form'], function () {

        var table = layui.table
            ,form = layui.form;
        //分类管理
        table.render({
            elem: '#LAY-task-list'
            ,method:'post'
            , id:'resource-list'
            , url: '@Html.Raw(Url.Action("List", "ScheduleTask"))' //模拟接口
            , page: true //开启分页
            , even: true
            , limit: 30
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'Name', title: '名称', edit: 'text', minWidth: 100 }
                , { field: 'Seconds', title: '秒间隔', edit: 'text', minWidth: 100 }
                , { field: 'Enabled', title: '启用', templet: '#enabledTpl', edit: 'text', minWidth: 100 }
                , { field: 'StopOnError', title: '意外终止', templet: '#stopOnErrorTpl', edit: 'text', minWidth: 100 }
                , { field: 'LastStartUtc', title: '开始更新',  minWidth: 100 }
                , { field: 'LastEndUtc', title: '最后更新',  minWidth: 100 }
                , { field: 'LastSuccessUtc', title: '成功时间',  minWidth: 100 }
            ]]
            , text: { none: '一条数据也没有^_^' }
        });

        //监听工具条
        table.on('tool(LAY-task-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("Delete")', { id: obj.data.Id });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                var tr = $(obj.tr);
                layer.open({
                    type: 2
                    , title: '编辑语言'
                    , content: '@Url.Action("Edit")?id=' + data.Id
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['500px', '450px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        });
        //监听单元格编辑
        table.on('edit(LAY-task-list)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.post('@Url.Action("TaskUpdate")', { id: data.Id,name:obj.data.Name,value:obj.data.Value});
        });

        var $ = layui.$, active = {  }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
